package com.qhit.dao;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 * TODO
 *
 * @author 村头老杨头
 * @version 1.0
 * @date 2021/10/12 15:24
 */
public class BaseDao {
    //创建C3P0数据源
    private static DataSource dataSource = new ComboPooledDataSource();
    //Dbutils工具类
    private static QueryRunner qrery =new QueryRunner(dataSource);
    public <T> T query(String sql, ResultSetHandler<T> rsh, Object... params){
        try {
            return qrery.query(sql,rsh,params);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
    public int update(String sql, Object... params){
        try {
            return qrery.update(sql,params);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return -1;
    }
}
